package com.反射Reflection.API;

import com.集合.Collection___.遍历对象方式2_增强for;

import javax.swing.*;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;

public class API1 {
    /// Class类对象的方法
    public static void main(String[] args) throws Exception {
        String str = "com.反射Reflection.API.B";
        //得到类对象
        Class<?> bClass = Class.forName(str);

        //1. getName:获取全类名
        System.out.println("\n------------getName:获取全类名--------------------------------");

        System.out.println("全类名 = "+bClass);

        //2. getSimpleName:获取简单类名
        System.out.println("\n------------getSimpleName:获取简单类名--------------------------------");
        System.out.println("简单类名 = "+bClass.getSimpleName());

        //3. getFields:获取所有public修饰的属性，包含本类以及父类的
        System.out.println("\n------------获取所有public修饰的属性，包含本类以及父类的-----------------------------------");

        Field[] fields = bClass.getFields();
        for (Field field : fields) {
            System.out.println(field.getAnnotatedType() +"  "+field.getName());
        }

        //4. getDeclaredFields:获取本类中所有属性
        System.out.println("\n------------getDeclaredFields:获取本类中所有属性-----------------------------------");
        Field[] declaredFields = bClass.getDeclaredFields();
        for (Field field : declaredFields) {
            System.out.println(field.getAnnotatedType() +"  "+field.getName());
        }

        //5. getMethods:获取所有public修饰的方法，包含本类以及父类的
        System.out.println("\n------------getMethods:获取所有public修饰的方法，包含本类以及父类的----------------------------");
        Method[] methods = bClass.getMethods();
        for (Method method : methods) {
            System.out.println(method.getReturnType()+"  "+method.getName());
        }

        //6. getDeclaredMethods:获取本类中所有方法
        System.out.println("\n-------------getDeclaredMethods:获取本类中所有方法(包括私有)----------------------------");
        Method[] methods2 = bClass.getDeclaredMethods();
        for (Method method : methods2) {
            System.out.println(method.getReturnType()+"  "+method.getName());
        }

        //7. getConstructors: 获取本类所有public修饰的构造器
        System.out.println("\n-------------getConstructors: 获取本类所有public修饰的构造器--------------------------");
        Constructor<?>[] constructors = bClass.getConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
        }

        //8. getDeclaredConstructors:获取本类中所有构造器
        System.out.println("\n-------------getDeclaredConstructors:获取本类中所有构造器-----------------------------");
        Constructor<?>[] constructors2 = bClass.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors2) {
            System.out.println(constructor);
        }
        
        //9. getPackage:以Package形式返回 包信息
        System.out.println("\n------------ getPackage:以Package形式返回 包信息----------------------------------");
        System.out.println(bClass.getPackage());

        //10.getSuperClass:以Class形式返回父类信息
        System.out.println("\n------------getSuperClass:以Class形式返回父类信息----------------------------------");
        System.out.println("父类信息 = "+bClass.getSuperclass());

        //11.getInterfaces:以Class[]形式返回接口信息
        System.out.println("\n---------------getInterfaces:以Class[]形式返回接口信息--------------------------------");
        Class<?>[] interfaces = bClass.getInterfaces();
        System.out.println(Arrays.toString(interfaces));
        

        //12.getAnnotations:以Annotation[] 形式返回注解信息
        System.out.println("\n---------------getAnnotations:以Annotation[] 形式返回注解信息--------------------------");
        Annotation[] annotations = bClass.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
    }
}
interface IA{}
interface IB{}
class A{
    public boolean a1;
    public int a2;

    private void geta1(){}
    private int geta2(){
        return 1;
    }

    
}

@Deprecated
@SwingContainer
class B extends A implements IA,IB{
    public static final int b1 = 10;
    protected String b2;

    int b3;
    private String b4;

    public B(){}
    private B(String str , int[] n){}
    protected B(int n){}
    B(boolean b){}

    public void r1(int n , String str,boolean b, double d){
    }
    protected int r2(){
        return 1;
    }
    String r3(){
        return null;
    }
    private void r4(){
    }
    private boolean r5(){
        return false;
    }
}